package com.ali.common;

import org.apache.commons.codec.digest.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class Md5Util {
    /**
     * MD5加密
     */
    public static String digestUtilsEncrypt(String content) {
        return DigestUtils.md5Hex(content);
    }

    /**
     * MD5加密
     */
    public static String encrypt(String content) {
        byte[] contentByte = content.getBytes(StandardCharsets.UTF_8);

        try {
            MessageDigest messageDigest = MessageDigest.getInstance("md5");
            byte[] digestByte = messageDigest.digest(contentByte);
            return HexUtil.encrypt(digestByte);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * MD5加密
     */
    public static String springEncrypt(String content) {
        byte[] contentByte = content.getBytes(StandardCharsets.UTF_8);
        return org.springframework.util.DigestUtils.md5DigestAsHex(contentByte);
    }
}